$(function () {
    $('#getcaptcha').click(function (event) {
        event.preventDefault();
        var self = $(this);
        var email = $("input[name='email']").val();

        if(!email){
            xtalert.alertInfoToast('请输入邮箱！');
            return;
        }
        zlajax.get({
            'url':'/cms/email_captcha/',
            'data':{
                'email':email
            },
            'success':function (data) {
                if(data['code'] == 200){
                    xtalert.alertSuccessToast('邮箱验证码发送成功！');
                    self.attr('disabled','disabled');
                    var timeCount = 60;
                    var timer = setInterval(function () {
                        timeCount--;
                        self.text(timeCount+'后重新发送');
                        if(timeCount<=0){
                            self.removeAttr('disabled')
                            clearInterval(timer);
                            self.text('发送验证码');
                        }
                    },1000);
                }else {
                    var message = data['message'];
                    xtalert.alertInfo(message)
                }
            },
            'fail':function (error) {
                xtalert.alertNetworkError()
            },
        });
    });
});
$(function () {
    $('#submit').click(function (event) {
        event.preventDefault()

        var emailE = $("input[name='email']");
        var captchaE = $("input[name='captcha']");

        var email = emailE.val();
        var captcha = captchaE.val();

        zlajax.post({
            'url':'/cms/resetemail/',
            'data':{
                'email':email,
                'captcha':captcha
            },
            'success':function (data) {
                if(data['code'] == 200){
                    emailE.val('');
                    captchaE.val('');
                    xtalert.alertSuccessToast('恭喜！邮箱修改成功！')
                }else{
                    emailE.val('');
                    captchaE.val('');
                    xtalert.alertInfo(data['message'])
                }
            },
            'fail':function (error) {
                xtalert.alertNetworkError('')
            }
        })
    })
})